package by.vkhalko.asamo.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.vkhalko.asamo.dataaccess.StatusDao;
import by.vkhalko.asamo.datamodel.Status;
import by.vkhalko.asamo.services.StatusService;

@Service
public class StatusServiceImpl implements StatusService {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(StatusServiceImpl.class);

	@Inject
	private StatusDao dao;

	@PostConstruct
	private void init() {
		LOGGER.info("Instance of StatusService is created. Class is: {}",
				getClass().getName());
	}

	@Override
	public Status get(Long id) {
		Status entity = dao.getById(id);
		return entity;
	}

	@Override
	public void saveOrUpdate(Status status) {
		if (status.getId() == null) {
			LOGGER.debug("Save new: {}", status);
			dao.insert(status);
		} else {
			LOGGER.debug("Update: {}", status);
			dao.update(status);
		}

	}

	@Override
	public void delete(Status status) {
		LOGGER.debug("Remove: {}", status);
		dao.delete(status.getId());

	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all statuses");
		dao.deleteAll();

	}

}
